A nearest neighbor technique such as k-nearest neighbor (“KNN”) is a machine learning method used to assign class membership to objects or data. For example, computer-based handwriting recognition attempts to recognize a character written by classifying the written character to one that is nearest to a stored representation of characters that make up the entire alphabet and/or numerical representations for a language. In some cases, the alphabet may contain thousands of characters such as those for Chinese or Japanese languages. A database for the alphabet may contain a handwritten sample for each character. When presented with a handwritten character by a user, the computer may attempt to assign one of the character labels in the database by extracting features from the user's handwritten character and determining those samples in the database that have similar features using a nearest neighbor technique. In KNN, the k most similar samples from the database may be determined and a character label may be assigned by voting. A database may contain millions of samples; thus, performing a search in such a large database is computationally expensive. In addition, the larger the number of characters, the more storage is required.